package com.example.guiguihomemedical.mapper;

import com.example.guiguihomemedical.entity.Record;
import com.example.guiguihomemedical.entity.Signing;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface SigningMapper {
    @Delete("delete from signing where idcard = #{id}")
    void delete(String id);
    @Insert("insert into signing(idcard, doctorid, starttime,endtime,servicebook,type) values(#{idcard},#{doctorid},#{starttime},#{endtime},#{servicebook},#{type})")
    void insert(Signing signing);
    @Select("select * from signing where idcard=#{id}")
    Signing getById(String id);
//    @Update("update signing set starttime = #{starttime}, endtime = #{endtime},servicebook = #{servicebook} where idcard = #{idcard}")
    void update(Signing signing);
    @Select("select * from signing where now() > starttime and now() <  endtime")
    List<Signing> getByNowServing();
    @Select("select * from (select * from record where idcard = #{idcard})a where idcard like '%'||#{searchIdcard}||'%' or name like '%'||#{searchIdcard}||'%' or phone like '%'||#{searchIdcard}||'%'")
    Record searchRecord(String idcard, String searchIdcard);
    @Select("select * from signing where now() > starttime and now() <  endtime AND idcard = #{idcard}")
    Signing getByIdcardNowServing(String idcard);
    @Select("select * from record where idcard=#{idcard}")
    Record getRecordByIdcard(String idcard);
@Select("select * from signing")
    List<Signing> getAll();
    @Select("SELECT * FROM signing WHERE idcard=#{id} ORDER BY endtime DESC LIMIT 1;")
    Signing getByIdOrserByendtime(String id);
    @Select("select * from signing WHERE idcard=#{idCard}")
    List<Signing> getAllByIdCard(String idCard);
    @Select("SELECT * FROM signing WHERE idcard=#{idCard} and starttime =#{starttime} and endtime = #{endtime};")
    Signing getByTimeServing(Date starttime, Date endtime,String idCard);
    @Select("select * from signing WHERE id=#{id}")
    Signing getByTrueId(int id);
    @Delete("delete from signing where id = #{id}")
    void deleteTrueId(int id);
    List<Record> searchNowServingRecord(Integer PageBegin,Integer PageSize,String searchString);
}
